//
//  Feed.m
//  IOSApplication
//
//  Created by 麻再挺 on 2019/5/22.
//  Copyright © 2019 麻再挺. All rights reserved.
//

#import "Feed.h"

@implementation Feed

// 获取 Feed 对象
// JSON 数据
+ (Feed *)getFeedWithObj: (id)object {
    Feed *feed = [Feed new];
//    NSLog(@"counts: %@", object[@"counts"]);
//    NSLog(@"isHistory: %@", object[@"is_history"]);
//    NSLog(@"message: %@", object[@"message"]);
//    NSLog(@"isMore: %@", object[@"more"]);
//    NSLog(@"result: %@", object[@"result"]);
    // 获取 counts
    feed.counts = [object[@"counts"] intValue];
    // 获取 isHistory
    feed.isHistory = [object[@"is_history"] intValue] == 0 ? NO : YES;
    // 获取 message
    feed.message = object[@"message"];
    // 获取 isMore
    feed.isMore = [object[@"more"] intValue] == 0 ? NO : YES;
    // 获取 result
    feed.result = object[@"result"];
    // 获取 feedList
    NSArray *array = object[@"feedList"];
    // 将 NSArray 转换为 NSArray<FeedItem *>
    NSMutableArray * mArray = [NSMutableArray new];
//    NSLog(@"%@", array[0]);
    // 遍历数组
    for (int i = 0; i < array.count; i++) {
        // 获取对象
        FeedItem *item = [FeedItem getFeedItemWithObj:array[i]];
        [mArray addObject:item];
    }
    feed.feedList = mArray;
    return feed;
}

@end
